package com.mike.sync.velocity;

import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.Template;
import org.apache.velocity.exception.ParseErrorException;
import org.apache.velocity.exception.ResourceNotFoundException;
import java.io.*;
import java.util.ArrayList;


public class Example {
	public Example(String templateFile) {
		try {
			//Velocity.init("d:\\velocity.properties");
			VelocityContext context = new VelocityContext();
			

			Template template = null;

			try {
				template = Velocity.getTemplate(templateFile);
			} catch (ResourceNotFoundException rnfe) {
				System.out.print(rnfe.toString());
			} catch (ParseErrorException pee) {
				
			}

			BufferedWriter writer = writer = new BufferedWriter(
					new OutputStreamWriter(System.out));

			if (template != null)
				template.merge(context, writer);

			writer.flush();
			writer.close();
			
			System.out.println(1);
		} catch (Exception e) {
			System.out.println(e);
		}
	}



	public static void main(String[] args) throws ResourceNotFoundException, ParseErrorException, Exception {
		/* first, get and initialize an engine */ 
		  VelocityEngine ve = new VelocityEngine(); 
		  ve.init(); 
		  /* next, get the Template */ 
		  File file = new File("d:\\velocity.vm"); 
		  System.out.println(file.exists()); 
		  Template t = ve.getTemplate( "d:\\velocity.vm" ); 
		  /* create a context and add data */ 
		  VelocityContext context = new VelocityContext(); 
		  context.put("name", "Billy"); 
		  context.put("site", "http://www.sina.com"); 
		  /* now render the template into a StringWriter */ 
		  StringWriter writer = new StringWriter(); 
		  t.merge( context, writer ); 
		  /* show the World */ 
		  System.out.println( writer.toString() ); 

	}
}
